class Generator < ActiveRecord::Base
  has_many :generations
  belongs_to :generation
  
  
  # gets the current generation.
  #
  # You could determine this logically from the generations table
  # but if the system every gets out of sync due to a bug (this will, 
  # of course never happen) the data. coruption would be catastrphic. 
  # So lets not rely on the generations table.
  def current_generation
    if self.current_generation_id.nil?
      logger.info "didn't find a current generation ID"
      return nil
    else
      ## this is no Generation.find( self.current_generation_id) because active record throws an
      ## exception if it can't find a record with this syntax. It's possible an over eager
      ## IT OPS person might delete a generation so we don't want to see exceptions
      return Generation.find(:first, :conditions => { :id => self.current_generation_id } )
    end
    
  end
end
